/*****************************************************************************
* | File      	:	DEV_Config.cpp
* | Author      : Waveshare team
* | Function    :
* | Info        :
*   Image scanning
*      Please use progressive scanning to generate images or fonts
*----------------
* |	This version:   V1.0
* | Date        :   2018-01-11
* | Info        :   Basic version
*
******************************************************************************/
#include "DEV_Config.h"


/******************************************************************************
function:	Initialize Arduino, Initialize Pins, and SPI
parameter:
Info:
******************************************************************************/
UBYTE DEV_Module_Init() {
    //set pin
//    pinMode(SPIRAM_CS, OUTPUT);
//    pinMode(SD_CS, OUTPUT);
    pinMode(epd_cs, OUTPUT);


    digitalWrite(epd_cs, 1);
//    SD_CS_1;
//    SPIRAM_CS_1;

    //set Serial
    // Serial.begin(115200);

    //set OLED SPI
    // SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
    spi_pg.setDataMode(SPI_MODE0);
    spi_pg.setBitOrder(MSBFIRST);
    spi_pg.setClockDivider(SPI_CLOCK_DIV4);
    spi_pg.begin();
    pinMode(epd_dc, OUTPUT);
    pinMode(epd_rst, OUTPUT);
    pinMode(epd_busy, INPUT);

    return 0;
}

/******************************************************************************
function:	Millisecond delay
parameter:
Info:
******************************************************************************/
void DEV_Delay_ms(UWORD xms) {
    Rtos::Delay(xms);
}

/******************************************************************************
function:	Analog microsecond delay
parameter:
Info:
******************************************************************************/
void DEV_Delay_us(UWORD xus) {
    for (int j = xus; j > 0; j--);
}

void DEV_Module_Exit() {
    digitalWrite(epd_cs, 1);
//    SD_CS_1;
//    SPIRAM_CS_1;
    digitalWrite(epd_rst, 0);
}
